import 'package:flutter/material.dart';
import 'package:hook_up_rent/routes/index.dart';

class RegisterPage extends StatefulWidget {
  const RegisterPage({Key key}) : super(key: key);

  @override
  _RegisterPageState createState() => _RegisterPageState();
}

class _RegisterPageState extends State<RegisterPage> {

  @override
  Widget build(BuildContext context) {
    // 优化
    print("执行");
    return Scaffold(
      appBar:AppBar(
        title:Text("注册"),
        centerTitle:true,
      ),
      body: SafeArea(
          minimum: EdgeInsets.all(30),
          child: ListView(
            children: [
              _buildUserField(),
              SizedBox(height: 10,),
              _buildPasswordFiled("密码","请输入密码"),
              SizedBox(height: 10,),
              _buildPasswordFiled("确认密码","请输入正确的密码"),
              SizedBox(height: 10,),
              _buildLoginButton(),
              SizedBox(height: 10,),
              _buildToLoginPage()
          ],
        ),
      ),
    );
  }

  _buildUserField(){
    return TextField(
      key:ValueKey(1),
      decoration: InputDecoration(
        labelText: "用户名",
        hintText: "请输入用户名"
      ),
    );
  }

  _buildPasswordFiled(String labelText,String hintText){
    return TextField(
      key:ValueKey(2),
      obscureText: true,
      decoration: InputDecoration(
        labelText: labelText,
        hintText: hintText,
      ),
    );
  }

  _buildLoginButton(){
    return ElevatedButton(
      key:ValueKey(3),
      onPressed: (){
      print("登录");
    }, child: Text("注册"));
  }

  _buildToLoginPage(){
    return Row(
      key:ValueKey(5),
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
      Text("已有账号?",key:ValueKey(6),),
      TextButton(
        key:ValueKey(4),
        onPressed: (){
        Navigator.pushReplacementNamed(context, MyRoutes.login);
      }, child: Text("去登录",style: TextStyle(color: Colors.green),))
    ],);
  }
}
